/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package general.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author isaias
 */
public class MySecurityUtil {
     private static MySecurityUtil instance = new MySecurityUtil();

    public static MySecurityUtil getInstance(){
        return instance;
    }

    private MySecurityUtil() {
    }

    public static String md5(String text){
        String sen = "";
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        BigInteger hash = new BigInteger(1, md.digest(text.getBytes()));
        sen = hash.toString(16);
        return sen;

    }

    public static String generatePassword() {
        return Long.toString(System.currentTimeMillis(), 36);
    }

    public static void main(String [] args){
        System.out.println(md5("123456"));
        System.out.println(md5("123"));
    }
}
